package com.dime.basic.service.impl;

import java.util.List;

import com.dime.basic.api.domain.DimeBasemaincheckconclusion;
import com.dime.basic.api.domain.DimeBasemaincheckconclusionadvice;
import com.dime.basic.mapper.DimeBasemaincheckconclusionadviceMapper;
import com.ruoyi.common.core.utils.DateUtils;
import com.ruoyi.common.core.utils.uuid.IdUtils;
import com.ruoyi.common.security.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.dime.basic.mapper.DimeBasemaincheckconclusionMapper;
import com.dime.basic.service.IDimeBasemaincheckconclusionService;

/**
 * 主检结论Service业务层处理
 *
 * @author Tiny
 * @date 2023-10-25
 */
@Service
public class DimeBasemaincheckconclusionServiceImpl implements IDimeBasemaincheckconclusionService
{
    @Autowired
    private DimeBasemaincheckconclusionMapper dimeBasemaincheckconclusionMapper;

    @Autowired
    private DimeBasemaincheckconclusionadviceMapper dimeBasemaincheckconclusionadviceMapper;

    /**
     * 查询主检结论
     *
     * @param id 主检结论主键
     * @return 主检结论
     */
    @Override
    public DimeBasemaincheckconclusion selectDimeBasemaincheckconclusionById(String id)
    {
        return dimeBasemaincheckconclusionMapper.selectDimeBasemaincheckconclusionById(id);
    }

    /**
     * 查询主检结论列表
     *
     * @param dimeBasemaincheckconclusion 主检结论
     * @return 主检结论
     */
    @Override
    public List<DimeBasemaincheckconclusion> selectDimeBasemaincheckconclusionList(DimeBasemaincheckconclusion dimeBasemaincheckconclusion)
    {
        return dimeBasemaincheckconclusionMapper.selectDimeBasemaincheckconclusionList(dimeBasemaincheckconclusion);
    }

    /**
     * 新增主检结论
     *
     * @param dimeBasemaincheckconclusion 主检结论
     * @return 结果
     */
    @Override
    public int insertDimeBasemaincheckconclusion(DimeBasemaincheckconclusion dimeBasemaincheckconclusion)
    {
        dimeBasemaincheckconclusion.setId(IdUtils.fastUUID());
        dimeBasemaincheckconclusion.setCreateTime(DateUtils.getNowDate());
        dimeBasemaincheckconclusion.setCreateBy(SecurityUtils.getUsername());
        setDimeBasemaincheckconclusion(dimeBasemaincheckconclusion);
        return dimeBasemaincheckconclusionMapper.insertDimeBasemaincheckconclusion(dimeBasemaincheckconclusion);
    }

    /**
     * 修改主检结论
     *
     * @param dimeBasemaincheckconclusion 主检结论
     * @return 结果
     */
    @Override
    public int updateDimeBasemaincheckconclusion(DimeBasemaincheckconclusion dimeBasemaincheckconclusion)
    {
        dimeBasemaincheckconclusion.setUpdateBy(SecurityUtils.getUsername());
        dimeBasemaincheckconclusion.setUpdateTime(DateUtils.getNowDate());
        setDimeBasemaincheckconclusion(dimeBasemaincheckconclusion);

        DimeBasemaincheckconclusionadvice dimeBasemaincheckconclusionadvice = new DimeBasemaincheckconclusionadvice();
        dimeBasemaincheckconclusionadvice.setMainconclusionId(dimeBasemaincheckconclusion.getId());
        dimeBasemaincheckconclusionadvice.setMainconclusionName(dimeBasemaincheckconclusion.getConclusion());
        dimeBasemaincheckconclusionadviceMapper.updateDimeBasemaincheckconclusionadviceByConclusionId(dimeBasemaincheckconclusionadvice);

        return dimeBasemaincheckconclusionMapper.updateDimeBasemaincheckconclusion(dimeBasemaincheckconclusion);
    }



    /**
     * 批量删除主检结论
     *
     * @param ids 需要删除的主检结论主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasemaincheckconclusionByIds(String[] ids)
    {
        return dimeBasemaincheckconclusionMapper.deleteDimeBasemaincheckconclusionByIds(ids);
    }

    /**
     * 删除主检结论信息
     *
     * @param id 主检结论主键
     * @return 结果
     */
    @Override
    public int deleteDimeBasemaincheckconclusionById(String id)
    {
        return dimeBasemaincheckconclusionMapper.deleteDimeBasemaincheckconclusionById(id);
    }

    private static void setDimeBasemaincheckconclusion(DimeBasemaincheckconclusion dimeBasemaincheckconclusion) {
        if(dimeBasemaincheckconclusion.getPassTag()==null){
            dimeBasemaincheckconclusion.setPassTag(0L);
        }
        if (dimeBasemaincheckconclusion.getRecheckTag()==null){
            dimeBasemaincheckconclusion.setRecheckTag("0");
        }
    }
}